package com.adpython.dao.jdoDao;

import java.util.List;

import javax.jdo.Extent;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import org.springframework.orm.jdo.support.JdoDaoSupport;

import com.adpython.dao.PageTabsDao;
import com.adpython.domain.PageTabs;

public class PageTabsJdoDao extends JdoDaoSupport implements PageTabsDao {
	
	public PageTabs getById(Long id){
		PersistenceManager pm = super.getPersistenceManager();
		PageTabs tab=null;
		Extent r = pm.getExtent (PageTabs.class, false);
		String filter = "id=="+id;
		Query query = pm.newQuery(r,filter);
		List<PageTabs> list = (List<PageTabs>) query.execute();
		if(!list.isEmpty())
			tab = list.get(0);
		return tab;
	}
	
	public List<PageTabs> getAll(){
		PersistenceManager pm = getPersistenceManager();
		Query query = pm.newQuery(PageTabs.class);
		query.setOrdering("rank asc");
		List<PageTabs> list = (List<PageTabs>) query.execute();
		return list;
	}
	
	public void save(PageTabs tab){
		getJdoTemplate().makePersistent(tab);
	}

	public void removeById(Long id){
		PersistenceManager pm = getPersistenceManager();
		Extent r = pm.getExtent (PageTabs.class, false);
		String filter = "id=="+id;
		Query query = pm.newQuery(r,filter);
		List<PageTabs> list = (List<PageTabs>) query.execute();
		if(!list.isEmpty()){
			PageTabs delTab = list.get(0);
			pm.deletePersistent(delTab);
		}
	}

}
